//
//  UiBottView.m
//  AccuroFit
//
//  Created by Yongfeng Li on 8/7/15.
//  Copyright (c) 2015 Nci Technology Inc. All rights reserved.
//

#import "UIBottView.h"
#import "AppDelegate.h"
#import "UIView+Extension.h"
#define BTNFont [UIFont systemFontOfSize:16]
@implementation UIBottView {
    UIImageView* _ivBkgd;
    //UIImageView* _ivhLine;
    
    //UIImageView* _ivvLine1;
    //UIImageView* _ivvLine2;
    
    /*UIImageView* _ivuArrow1;
    UIImageView* _ivuArrow2;
    UIImageView* _ivuArrow3;
    UIImageView* _ivuArrow4;*/
    UIView *topLine;
    UIView *topTwoLine;
    UIView *topThreeLine;
    /*UIButton* _btnHrate;
    UIButton* _btnBlood;
    UIButton* _btnSteps;
    UIButton* _btnWeigh;*/
    short _nSelMeasIdx;
    UIButton* _btnMeasTxt[4];
    UIButton* _btnMeasImg[4];
    id _bvDelegate;
    
    
    UILabel* _lblHrate;
    UILabel* _lblBlood;
    UILabel* _lblSteps;
    UILabel* _lblWeigh;
    
    UILabel* _lblBodyWgt;
    UILabel* _lblBodyFat;
    UILabel* _lblWgtTips;
    UILabel* _lblFatTips;
  
  /*short _nAvgHrate;
  short _nMaxHrate;
  short _nMinHrate;
  
  NSDate* _dtMeasStart;
  NSDate* _dtMeas;
  NSDate* _dtLast;*/
}

@synthesize m_nSelMeasIdx = _nSelMeasIdx;

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        //self.backgroundColor = [UIColor blueColor];
        _ivBkgd = [[UIImageView alloc] initWithFrame:CGRectMake(0, -6, frame.size.width, frame.size.height)];
        UIImage* iBkgd = [[UIImage imageNamed:@"ic-bottbkgd.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        _ivBkgd.contentMode = UIViewContentModeScaleAspectFit;
        
        topLine = [[UIView alloc] initWithFrame:CGRectMake(0, -6, frame.size.width / 3, 1.0)];
        topLine.backgroundColor = [UIColor grayColor];
        topLine.alpha = 0.0;
        [self addSubview:topLine];
        
        topTwoLine = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(topLine.frame), -6, frame.size.width / 3, 1.0)];
        topTwoLine.backgroundColor = [UIColor grayColor];
        topTwoLine.alpha = 0.7;
        [self addSubview:topTwoLine];
        
        topThreeLine = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(topTwoLine.frame), -6, frame.size.width / 3, 1.0)];
        topThreeLine.backgroundColor = [UIColor grayColor];
        topThreeLine.alpha = 0.7;
        [self addSubview:topThreeLine];
        
        UIView *mLine = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width / 3, CGRectGetMaxY(topLine.frame), 1.0, frame.size.height / 2)];
        mLine.backgroundColor = [UIColor grayColor];
        mLine.alpha = 0.7;
        [self addSubview:mLine];
        
        UIView *mmLine = [[UIView alloc] initWithFrame:CGRectMake(frame.size.width / 3 * 2, CGRectGetMaxY(topLine.frame), 1.0, frame.size.height / 2)];
        mmLine.backgroundColor = [UIColor grayColor];
        mmLine.alpha = 0.7;
        [self addSubview:mmLine];
        
        UIView *dLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(mLine.frame), frame.size.width, 1.0)];
        dLine.backgroundColor = [UIColor grayColor];
        dLine.alpha = 0.7;
        [self addSubview:dLine];
        
        //_ivBkgd.alpha = 1.0;
        [_ivBkgd setImage:iBkgd];
//        [self addSubview:_ivBkgd];
        
        //UIColor* colBkgd = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"ic-bottbkgd.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        //self.backgroundColor = colBkgd;
        
        //self.backgroundColor = [UIColor clearColor];
        //self.backgroundColor = [UIColor colorWithWhite:0.149 alpha:0.528];
        
        //_nSelBtn = -1;
        [self initialize: frame];
        _nSelMeasIdx = 3;
    }
  
  /*_nAvgHrate = 0;
  _nMaxHrate = 0;
  _nMinHrate = 0;
  
  _dtMeasStart = [NSDate date];
  _dtMeas = [NSDate date];
  _dtLast = [NSDate date];*/
  
    return self;
}

- (void) initialize:(CGRect)frame
{
    BOOL bIpad = frame.size.width > 700;
    BOOL bWider = frame.size.width > 320;
    BOOL bPlus =  !bIpad && frame.size.height >= 269;
  
  AppDelegate* pApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    CGRect rt = CGRectMake(0, 0, frame.size.width, frame.size.height);
    //BOOL bIpad = frame.size.width > 700;
    
    //UIImage* iCon = [[UIImage imageNamed:@"ic-hline.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    /*UIImage* iCon = [[UIImage imageNamed:@"ic-horline.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    rt.origin.y = frame.size.height/2.0 - iCon.size.height/2;
    rt.size.height = iCon.size.height;
    _ivhLine  = [[UIImageView alloc] initWithFrame:rt];
    [_ivhLine setImage:iCon];
    [self addSubview:_ivhLine]*/;
    
    //iCon = [[UIImage imageNamed:@"ic-vline.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    /*iCon = [[UIImage imageNamed:@"ic-verline.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    rt.origin.x = frame.size.width / 3.0;
    rt.origin.y = bIpad? 10: 20;
    if(frame.size.height <= 196)
        rt.origin.y += 10;
    rt.size.height = frame.size.height / 2.5;
    rt.size.width = iCon.size.width;
    _ivvLine1  = [[UIImageView alloc] initWithFrame:rt];
    [_ivvLine1 setImage:iCon];
    [self addSubview:_ivvLine1];
    
    rt.origin.x = frame.size.width * 2 / 3.0;
    _ivvLine2  = [[UIImageView alloc] initWithFrame:rt];
    [_ivvLine2 setImage:iCon];
    [self addSubview:_ivvLine2];*/
    
  float fImgScale = 1.0;
  UIImage* iCon = [pApp getImageScale:@"btn-hrate-gry.png" scale:fImgScale]; //[[UIImage imageNamed:@"btn-hrate-gry.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    CGSize iconSize;
    fImgScale = bIpad?1:0.5;
    if (fImgScale == 0.5) {
        iconSize = CGSizeMake(49, 49);
    } else if (fImgScale == 1){
         iconSize = CGSizeMake(98, 98);
    }
    CGRect iconFrame = [UIScreen mainScreen].bounds;
    CGFloat W = iconFrame.size.width;
    
    iconSize = CGSizeMake(W / 6, W / 6);
    
  rt.origin.x = frame.size.width / 6.0 -iconSize.width + 20;
  rt.origin.y = frame.size.height/2.0 - iconSize.height * 3;
  if(bIpad)
    rt.origin.y += 10;
  else if(bPlus)
    rt.origin.y -= 8;
  else if(bWider)
    rt.origin.y -= 1;
  else if(frame.size.height <= 169)
    rt.origin.y += 8;
  

    
  rt.origin.x += bIpad?40:10;
  rt.origin.y += bIpad?140:60;
  rt.size.width = iconSize.width;
  rt.size.height = iconSize.height;
  /*_ivuArrow1 = [[UIImageView alloc] initWithFrame:rt];
  [_ivuArrow1 setImage:iCon];
  [self addSubview:_ivuArrow1];*/
  _btnMeasImg[0] = [[UIButton alloc] initWithFrame:rt];
  [_btnMeasImg[0] setBackgroundImage:iCon forState:UIControlStateNormal];
  [_btnMeasImg[0] setBackgroundImage:[UIImage imageNamed:@"btn-hrate-pur.png"] forState:UIControlStateSelected];
  [_btnMeasImg[0] addTarget:self action:@selector(onMeasButtonsAct:) forControlEvents:UIControlEventTouchUpInside];
  [self addSubview:_btnMeasImg[0]];
  
  /*[_btnHrate setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  [_btnHrate setTitle:@"Avg Heart Rate" forState:UIControlStateNormal];
  [self addSubview:_btnHrate];*/
    fImgScale = 1.0;
  iCon = [pApp getImageScale:@"btn-bldp-gry.png" scale:fImgScale];
  rt.origin.x += frame.size.width / 3.0;
  
  
    _btnMeasImg[1] = [[UIButton alloc] initWithFrame:rt];
    [_btnMeasImg[1] setBackgroundImage:iCon forState:UIControlStateNormal];
    [_btnMeasImg[1] setBackgroundImage:[UIImage imageNamed:@"btn-bldp-pred.png"] forState:UIControlStateSelected];
    [_btnMeasImg[1] addTarget:self action:@selector(onMeasButtonsAct:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnMeasImg[1]];
    
    iCon = [pApp getImageScale:@"btn-step-gry.png" scale:fImgScale];
     rt.origin.x += frame.size.width / 3.0;
    _btnMeasImg[2] = [[UIButton alloc] initWithFrame:rt];
    [_btnMeasImg[2] setBackgroundImage:iCon forState:UIControlStateNormal];
    [_btnMeasImg[2] setBackgroundImage:[UIImage imageNamed:@"btn-step-green.png"] forState:UIControlStateSelected];
    [_btnMeasImg[2] addTarget:self action:@selector(onMeasButtonsAct:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnMeasImg[2]];

  iCon = [pApp getImageScale:@"btn-weigh-gry.png" scale:fImgScale];
  rt.origin.x -= frame.size.width / 3.0 - (bIpad?10:0);
  rt.origin.y += frame.size.height / 2.0 + (bIpad?-10:(bWider?5:10));
  if (bIpad)
    rt.origin.y += 12;
  else if(bPlus)
    rt.origin.y += 10;
  else if(frame.size.height <= 169)
    rt.origin.y += 8;
  else
    rt.origin.y -= 6;
    rt.origin.y = CGRectGetMaxY(_btnMeasImg[2].frame) + [UIScreen mainScreen].bounds.size.height / 13;
    rt.size.width = W / 7;
    rt.size.height = rt.size.width;
  _btnMeasImg[3] = [[UIButton alloc] initWithFrame:rt];
  [_btnMeasImg[3] setBackgroundImage:iCon forState:UIControlStateNormal];
  [_btnMeasImg[3] setBackgroundImage:[UIImage imageNamed:@"btn-weigh-blu.png"] forState:UIControlStateSelected];
  [_btnMeasImg[3] addTarget:self action:@selector(onMeasButtonsAct:) forControlEvents:UIControlEventTouchUpInside];
  [self addSubview:_btnMeasImg[3]];
    
  rt.origin.x += frame.size.width / 3.0;
  rt.origin.y -= frame.size.height / 2.0;
  if(frame.size.width <= 320)
    rt.origin.y += 10;
  /*_ivuArrow3 = [[UIImageView alloc] initWithFrame:rt];
  [_ivuArrow3 setImage:iCon];
  [self addSubview:_ivuArrow3];*/
    
  [self createBottomButtons: frame.size.width frmHgt:frame.size.height];
}

- (void) createBottomButtons:(CGFloat)W frmHgt:(CGFloat)H
{
    BOOL bIpad = W > 700;
    BOOL bWider = W > 320;
    BOOL bPlus = !bIpad && H >= 269;
    
    CGFloat yPos = H / 4.5 - 10;
    if(bIpad)
        yPos += 15;
    else if(bPlus)
        yPos += 20;
    else if(H <= 169)
        yPos += 10;
    
    CGFloat fBtnWid = W / 3.0 - 12;//bIpad? 230: 120;
    CGFloat xPos = bIpad ? 20: 10;
  yPos += bIpad?50:35;
    
    _lblHrate = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos-40, fBtnWid, 30)];
    _lblHrate.textColor = [UIColor whiteColor];
    _lblHrate.textAlignment = NSTextAlignmentCenter;
    _lblHrate.text = @"--- bpm";
    [self addSubview:_lblHrate];
  _lblHrate.hidden = YES;
  
  UIColor* texColor = [UIColor colorWithRed:112.0/255 green:42.0/255 blue:135.0/255 alpha:0.75];
    _btnMeasTxt[0] = [[UIButton alloc] initWithFrame:CGRectMake(xPos, yPos-(bWider?15:20), fBtnWid, 40)];
//    _btnMeasTxt[0].titleLabel.font = [UIFont systemFontOfSize:bIpad? 16: 12.6];
    _btnMeasTxt[0].titleLabel.font = BTNFont;
    [_btnMeasTxt[0] setTitleColor: texColor forState:UIControlStateNormal];
    [_btnMeasTxt[0] setTitle:NSLocalizedString(@"Heart Rate", nil) forState:UIControlStateNormal];
    [_btnMeasTxt[0] addTarget:self action:@selector(onMeasButtonsAct:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview: _btnMeasTxt[0]];
    _btnMeasImg[0].center = _btnMeasTxt[0].center;
    _btnMeasImg[0].centerY = _btnMeasTxt[0].centerY - _btnMeasImg[0].size.width / 1.6;
    _btnMeasTxt[0].backgroundColor = [UIColor clearColor];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"UpdateLableFrame" object:_btnMeasTxt[0]];
 
    xPos += W / 3.0;
    _lblBlood = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos-40, fBtnWid, 30)];
    _lblBlood.font = [UIFont systemFontOfSize:13.6];
    _lblBlood.textColor = [UIColor whiteColor];
    _lblBlood.textAlignment = NSTextAlignmentCenter;
    _lblBlood.text = @"---/-- mmHg";
    [self addSubview:_lblBlood];
  _lblBlood.hidden = YES;
    
    _btnMeasTxt[1]= [[UIButton alloc] initWithFrame:CGRectMake(xPos, yPos-(bWider?15:20), fBtnWid, 40)];
//    _btnMeasTxt[1].titleLabel.font = [UIFont systemFontOfSize:bIpad? 16:12.6];
    _btnMeasTxt[1].titleLabel.font = BTNFont;
    [_btnMeasTxt[1] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_btnMeasTxt[1] setTitle:NSLocalizedString(@"Blood Pressure", nil) forState:UIControlStateNormal];
    [_btnMeasTxt[1] addTarget:self action:@selector(onMeasButtonsAct:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnMeasTxt[1]];
    _btnMeasImg[1].center = _btnMeasTxt[1].center;
    _btnMeasImg[1].centerY = _btnMeasImg[0].centerY;
    xPos += W / 3.0;
    _lblSteps = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos-40, fBtnWid, 30)];
    _lblSteps.textColor = [UIColor whiteColor];
    _lblSteps.textAlignment = NSTextAlignmentCenter;
    _lblSteps.text = @"----";
    [self addSubview:_lblSteps];
  _lblSteps.hidden = YES;
    
    _btnMeasTxt[2] = [[UIButton alloc] initWithFrame:CGRectMake(xPos, yPos-(bWider?15:20), fBtnWid, 40)];
//    _btnMeasTxt[2].titleLabel.font = [UIFont systemFontOfSize:bIpad? 16:12.6];
    _btnMeasTxt[2].titleLabel.font = BTNFont;
    [_btnMeasTxt[2] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_btnMeasTxt[2] setTitle:NSLocalizedString(@"Pedometer", nil) forState:UIControlStateNormal];
    [_btnMeasTxt[2] addTarget:self action:@selector(onMeasButtonsAct:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnMeasTxt[2]];
    _btnMeasImg[2].center = _btnMeasTxt[2].center;
    _btnMeasImg[2].centerY = _btnMeasImg[0].centerY;
    
    //second line
  xPos =  (bIpad ? 20: 10) +  W / 3.0;
  yPos = H/2 + (bIpad? -5: 10);
  if(bIpad)
    yPos += 15;
  if(bWider)
    yPos -= 5;
  else if(H <= 169)
    yPos -= 7;
  else
    yPos -= 0;
    
    _lblWeigh = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos, fBtnWid, 30)];
    _lblWeigh.textColor = [UIColor whiteColor];
    _lblWeigh.textAlignment = NSTextAlignmentCenter;
    _lblWeigh.text = @"---.-";
    [self addSubview:_lblWeigh];
  _lblWeigh.hidden = YES;

  
  if(bIpad)
    yPos += 80;
  else if(bPlus)
    yPos += 60;
  else
    yPos += 30;
  
    _btnMeasTxt[3] = [[UIButton alloc] initWithFrame:CGRectMake(xPos, yPos+(bIpad?20:(bWider?18:15)), fBtnWid, 40)];
//    _btnMeasTxt[3].titleLabel.font = [UIFont systemFontOfSize:bIpad? 20:14.6];
    _btnMeasTxt[3].titleLabel.font = BTNFont;
    [_btnMeasTxt[3] setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_btnMeasTxt[3] setTitle:NSLocalizedString(@"Body Weight", nil) forState:UIControlStateNormal];
    [_btnMeasTxt[3] addTarget:self action:@selector(onMeasButtonsAct:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_btnMeasTxt[3]];
    
    _btnMeasImg[3].center = _btnMeasTxt[3].center;
    _btnMeasImg[3].centerY = _btnMeasTxt[3].centerY - _btnMeasImg[3].size.width / 1.4;
    
    xPos =  (bIpad ? 20: 5);
    _lblBodyWgt = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos-10, fBtnWid, 30)];
    _lblBodyWgt.textColor = [UIColor blackColor];
    _lblBodyWgt.textAlignment = NSTextAlignmentCenter;
  _lblBodyWgt.font = Bold(21);
    _lblBodyWgt.text = @"--.-";
    [self addSubview:_lblBodyWgt];
    
    xPos += W * 2.0 / 3.0;
    _lblBodyFat = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos-10, fBtnWid, 30)];
    _lblBodyFat.textColor = [UIColor blackColor];
    _lblBodyFat.textAlignment = NSTextAlignmentCenter;
  _lblBodyFat.font = Bold(21);
    _lblBodyFat.text = @"--.-";
    [self addSubview:_lblBodyFat];
    
     xPos =  bIpad ? 20: 10;
     yPos += 40;
    _lblWgtTips = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos-20, fBtnWid, 30)];
    _lblWgtTips.font = [UIFont systemFontOfSize: 15];
    _lblWgtTips.textColor = [UIColor blackColor];
    _lblWgtTips.textAlignment = NSTextAlignmentCenter;
    _lblWgtTips.text = bIpad?@"Body Wgt":NSLocalizedString(@"Weight", nil);
    [self addSubview:_lblWgtTips];
    
    xPos += W * 2.0 / 3.0;
    _lblFatTips = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos-20, fBtnWid, 30)];
    _lblFatTips.font = [UIFont systemFontOfSize: 15];
    _lblFatTips.textColor = [UIColor blackColor];
    _lblFatTips.textAlignment = NSTextAlignmentCenter;
    _lblFatTips.text = NSLocalizedString(@"Body Fat", nil);
    [self addSubview:_lblFatTips];
    _lblWgtTips.centerX =  _btnMeasTxt[0].centerX;
    _lblBodyWgt.centerX =  _btnMeasTxt[0].centerX;
    _lblFatTips.centerX =  _btnMeasTxt[2].centerX;
    _lblBodyFat.centerX =  _btnMeasTxt[2].centerX;
    _lblBodyFat.centerY = _btnMeasImg[3].centerY;
    _lblBodyWgt.centerY = _btnMeasImg[3].centerY;
}

//meas button action
- (void) onMeasButtonsAct:(id)sender
{
  UIColor* colGryText = [UIColor grayColor];
  UIColor* colSelText = [UIColor blackColor];
  if(_nSelMeasIdx >= 0)
    _btnMeasImg[_nSelMeasIdx].selected = NO;
  if(sender == _btnMeasImg[0] || sender == _btnMeasTxt[0]) {
    _nSelMeasIdx = 0;
    colSelText = [UIColor colorWithRed:112.0/255 green:42.0/255 blue:135.0/255 alpha:1.0];
      topLine.alpha = 0.0;
      topTwoLine.alpha = 0.7;
      topThreeLine.alpha = 0.7;
  }
  else  if(sender == _btnMeasImg[1] || sender == _btnMeasTxt[1]) {
    _nSelMeasIdx = 1;
    colSelText = [UIColor colorWithRed:215.0/255 green:26.0/255 blue:117.0/255 alpha:1.0];
      topLine.alpha = 0.7;
      topTwoLine.alpha = 0.0;
      topThreeLine.alpha = 0.7;
  }
  else  if(sender == _btnMeasImg[2] || sender == _btnMeasTxt[2]) {
    _nSelMeasIdx = 2;
    colSelText = [UIColor colorWithRed:0.0/255 green:144.0/255 blue:81.0/255 alpha:1.0];
      topLine.alpha = 0.7;
      topTwoLine.alpha = 0.7;
      topThreeLine.alpha = 0.0;
  }
  else  if(sender == _btnMeasImg[3] || sender == _btnMeasTxt[3]) {
    _nSelMeasIdx = 3;
    colSelText = [UIColor colorWithRed:0.0/255 green:140.0/255 blue:189.0/255 alpha:1.0];
      topLine.alpha = 0.7;
      topTwoLine.alpha = 0.7;
      topThreeLine.alpha = 0.7;
  }
  
  for(int i=0; i<4; i++) {
    [_btnMeasTxt[i] setTitleColor:(i==_nSelMeasIdx)?colSelText:colGryText forState:UIControlStateNormal];
  }
  
  _btnMeasImg[_nSelMeasIdx].selected = YES;
  if (_bvDelegate && [_bvDelegate respondsToSelector:@selector(onButtonTaps:)]) {
    [_bvDelegate onButtonTaps:_nSelMeasIdx];
  }
}

- (void) setMeasIdx: (short) nIdx
{
    if(_nSelMeasIdx >= 0)
        _btnMeasImg[_nSelMeasIdx].selected = NO;
    _nSelMeasIdx = nIdx;
    _btnMeasImg[nIdx].selected = YES;
}


- (void) setWgtMeasVal:(float)fWgt unit:(Byte)nWu
{
  _lblWeigh.text = (fWgt>0.0)?[NSString stringWithFormat:@"%.1f %@", fWgt, ((nWu==2)?@"kg": @"kg")]: @"---.-";
}

- (void) setHrtMeasVal:(short)nHrate
{
  _lblHrate.text = (nHrate>0)?[NSString stringWithFormat:@"%d bpm", nHrate]: @"--- bpm";
}

- (void) setBdpMeasVal:(short)nBldph low:(short)nBldpl
{
    _lblBlood.text = (nBldph>0)?[NSString stringWithFormat:@"%d/%d mmHg", nBldph, nBldpl]: @"---/-- mmHg";
}

- (void) setStepMeasVal:(int)nSteps
{
    _lblSteps.text = (nSteps>0)?[NSString stringWithFormat:@"%d", nSteps]:@"----";
}

- (void) setFatWgtVal:(float)fFat wgt:(float) fWgt
{
  if(fFat > 0.0)
    _lblBodyFat.text = [NSString stringWithFormat:@"%.1f %%", fFat];
  else
    _lblBodyFat.text = @"--.-";
  if(fWgt > 0.0)
    _lblBodyWgt.text = [NSString stringWithFormat:@"%.1f kg", fWgt];
  else
    _lblBodyWgt.text = @"--.-";
}

@end
